Put_Sprite_XOR:
; A = x coordinate
; L = y coordinate
; B = number of rows
; 
; IX = address of sprite
    LD     H, 0
    LD     D, H
    LD     E, L
    ADD    HL, HL
    ADD    HL, DE
    ADD    HL, HL
    ADD    HL, HL

    LD     E, A
    SRL    E
    SRL    E
    SRL    E
    ADD    HL, DE

    LD     DE, plotsscreen
    ADD    HL, DE
   
    
    AND    7
    JR     Z, _AlignedXOR

    LD     C, A
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL    
    
_RowLoopXOR:

    PUSH   BC
    
    ;Stores width into B, which will be decreased 1 by 1 until one row is complete
    LD A, (Sprite_Width)
    LD B, A
    

_ColumnLoopXOR:
    PUSH BC 
       
    LD     B, C
    LD     C, (IX)
    XOR    A

_ShiftLoopXOR:
    SRL    C
    RRA
  
    DJNZ   _ShiftLoopXOR
  

    INC    HL
    XOR   (HL)
    LD     (HL), A

    DEC    HL
    LD     A, C
    XOR    (HL)
    LD     (HL), A

    POP BC
    INC HL
    INC IX
  
    DJNZ _ColumnLoopXOR
   
    ADD    HL, DE
   
    POP    BC
    DJNZ   _RowLoopXOR
    
    RET

_AlignedXOR:
   
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL  
     
_PutLoopXOR:
    PUSH BC
    LD A, (Sprite_Width)
    LD B, A 

_PutLoopXOR2:
    
    LD     A, (IX)
    XOR (HL)
    LD     (HL), A
    INC  IX
  
    INC HL
    DJNZ _PutLoopXOR2
_PutLoopXORAdd:
    POP BC
    
    ;ADD    HL, DE
    ;DJNZ _PutLoop 
 ADD HL, DE
 DJNZ _PutLoopXOR
    RET
